#include"head.h"


void Calculate(Information s[], int n)		/*计算个人月工资*/
{
	
	int age;
	
	for (int i=0; i<n; i++)
	{
		age=s[i].nowyear-s[i].startwork_year;
		if (s[i].ill>0)
		{
			if ( s[i].nowmonth < s[i].startwork_month || (s[i].nowmonth == s[i].startwork_month && s[i].nowday < s[i].startwork_day))
			{
				age--;
			}
				
			if (age<2)
			{
				s[i].sickleave_coefficient=0.6;
			}
			else if (age>=2&&age<4)
			{
				s[i].sickleave_coefficient=0.7;
			}
			else if (age>=4&&age<6)
			{
				s[i].sickleave_coefficient=0.8;
			}
			else if (age>=6&&age<8)
			{
				s[i].sickleave_coefficient=0.9;
			}
			else
			{
				s[i].sickleave_coefficient=1;
			}
			double num;
			num=1-s[i].sickleave_coefficient;
			s[i].sick=((double)s[i].base/30.0)*num*s[i].ill;
			s[i].realmoney=s[i].base+s[i].job+s[i].price+s[i].post+s[i].live+s[i].overtime*s[i].add_work+s[i].night_differential*s[i].night-s[i].sick-s[i].thing*s[i].busy_thing-s[i].free*s[i].free_work-s[i].other;
		}
		else
		{
			s[i].sick=0;
			s[i].realmoney=s[i].base+s[i].job+s[i].price+s[i].post+s[i].live+s[i].overtime*s[i].add_work+s[i].night_differential*s[i].night-s[i].sick-s[i].thing*s[i].busy_thing-s[i].free*s[i].free_work-s[i].other;
		}
	}
	
	return ;
}

void Calculate_individual(Information s[], int n)	/*计算指定职员的月工资*/
{
	Calculate(s, n);
	
	fflush(stdin);
	char Appointname[20];
	printf("请输入想要计算工资的职员姓名：");
	gets(Appointname);
	
	int flag;
	for (int i=0; i<n; i++)
	{
		if (strcmp(s[i].name,Appointname)==0)
		{
			flag=1;
			printf("职员%s的月工资为：%lf\n",Appointname,s[i].realmoney);
		}

	}
	if (flag!=1)
	{
		printf("未找到！\n");
	}
	return ;
}

void Calculate_section(Information s[], int n)	/*计算部门月工资*/
{
	fflush(stdin);
	char appointsection[20];
	printf("请输入想要计算月工资的部门：");
	gets(appointsection);
	
	Calculate(s, n);
	
	double sum=0;
	int flag;
	for (int j=0; j<n; j++)
	{
		if (strcmp(s[j].section,appointsection)==0)
		{
			flag=1;
			sum=sum+s[j].realmoney;
		}
		
	}
	if (flag!=1)
	{
		printf("未找到！");
	}
	else
	{
		printf("%s部门的月工资为%lf\n", appointsection, sum);
	}
	
	
	return ;
}

void Calculate_all_school(Information s[], int n)	/*计算全校月工资*/
{
	Calculate(s, n);
	for(int i=0; i<n; i++)
	{
		s[i].realmoney=s[i].base+s[i].job+s[i].price+s[i].post+s[i].live+s[i].overtime*s[i].add_work+s[i].night_differential*s[i].night-s[i].sick-s[i].thing*s[i].busy_thing-s[i].free*s[i].free_work-s[i].other;
		printf("%s的月工资为：%lf\n", s[i].name, s[i].realmoney);
	}
	
	double sum;
	for(int j=0; j<n; j++)
	{
		sum=sum+s[j].realmoney;
	}
	printf("\n全校的月工资为%lf\n", sum);
	return ;
}